/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.apps.epocket.quartz;

import com.google.inject.Inject;
import com.google.inject.Injector;
import org.quartz.Job;
import org.quartz.SchedulerException;
import org.quartz.spi.JobFactory;
import org.quartz.spi.TriggerFiredBundle;

/**
 *
 * @author Administrator
 */
public class GuiceJobFactory implements JobFactory {

    @Inject Injector injector;

    public Job newJob(TriggerFiredBundle bundle) throws SchedulerException {
        Job job = null;
        try {
            job = (Job) injector.getInstance(bundle.getJobDetail().getJobClass());
            injector.injectMembers(job);
        } catch (Exception ex) {
            throw new SchedulerException(ex);
        }
        return job;
    }

}
